package whf.framework.report.jasper;

import java.io.OutputStream;
import java.util.Map;

import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperPrint;
import whf.framework.util.Utils;

/**
 * @author King
 * @create Jan 18, 2008 2:44:47 PM
 */
public class PdfJasperReportExporter extends JasperReportExporter {

	/* (non-Javadoc)
	 * @see whf.framework.report.jasper.JasperReportExporter#exportReport(net.sf.jasperreports.engine.JasperPrint, java.io.OutputStream)
	 */
	@Override
	protected void exportJasperReport(JasperPrint jasperPrint, OutputStream out) throws Exception {
		byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint);
		out.write(bytes, 0, bytes.length);
		out.flush();
	}

	/* (non-Javadoc)
	 * @see whf.framework.report.ReportExporter#getContentType()
	 */
	public String getContentType() {
		return "application/pdf;charset=UTF-8";
	}

	/* (non-Javadoc)
	 * @see whf.framework.report.ReportExporter#getHeaders()
	 */
	public Map<String, String> getHeaders() {
		Map<String, String> result = Utils.newHashMap();
		result.put("Content-disposition", "attachment; filename=" + this.reportDescriptor.getFileName());
		return result;
	}
}
